import { RosterInterface } from '@/api/interface/personnel/roster/roster';
import { BasicForm } from '@/components/ProForm/interface/index';

/**
 * 其他信息
 */

export function useOtherInfoForm(getOtherInfoData: Function) {
  let otherInfoForm = reactive<BasicForm<RosterInterface.ReqOtherInfoSave>>({
    form: {
      id: null,
      rosterId: null,
      dormNumber: ''
    },
    title: '',
    minWidth: 660,
    labelWidth: [100, 120],
    visible: false,
    formAttrs: {
      labelWidth: '120px'
    },
    options: [
      {
        type: 'input',
        label: 'ID',
        prop: 'id',
        hide: true
      },
      {
        type: 'input',
        label: '主表id',
        prop: 'rosterId',
        hide: true
      },
      {
        type: 'input',
        hide: false,
        prop: 'dormNumber',
        label: '宿舍编号',
        attrs: {}
        // rules: [
        //   {
        //     required: true,
        //     message: "宿舍编号",
        //     trigger: "blur"
        //   }
        // ]
      }
    ]
  });

  /**
   * 打开表单
   */
  const openOtherInfoForm = (title: string, row?) => {
    formOpen(otherInfoForm, title, row);
  };

  /**
   * @description: 保存表单数据
   * @return {*}
   */
  const saveAddOtherInfoForm = async form => {
    await otherInfoSave(form);
    otherInfoForm.visible = false;
    elMessage();
    getOtherInfoData();
  };

  return { otherInfoForm, saveAddOtherInfoForm, openOtherInfoForm };
}
